#include<bits/stdc++.h>
using namespace std;const int N=2e5+5,M=1<<15;using ll=long long;
int n,q,m,c[N],ans[N],fa[N],siz[N],s[15],hs[M],top;
vector<int>v[N],p[N],e[N];vector<pair<int,int>>g[N];pair<int,int>st[N];
inline int get(int u){while(u!=fa[u])u=fa[u];return u;}
inline int Merge(int x,int y){x=get(x),y=get(y);if(x==y)return x;
	if(siz[x]<siz[y])swap(x,y);siz[x]+=siz[y],fa[y]=x,st[++top]={x,y};return x;
}
void dfs(int now){int lst=top;
	for(auto u:p[hs[now]]){int rt=get(u);for(auto i:v[u])if(now>>c[i]&1)rt=Merge(rt,i);}
	for(auto i:g[now])ans[i.second]=siz[get(i.first)];for(auto to:e[now])dfs(to);
	while(top>lst)siz[st[top].first]-=siz[st[top].second],fa[st[top].second]=st[top].second,top--;
}
int main(){freopen("tree.in","r",stdin),freopen("tree.out","w",stdout);
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	cin>>n>>q>>m;for(int i=1;i<=n;i++)cin>>c[i],p[c[i]].push_back(i);
	for(int x,i=2;i<=n;i++)cin>>x,v[x].push_back(i),v[i].push_back(x);
	for(int i=1;i<=n;i++)s[c[i]]+=v[i].size();
	for(int v,x,i=1;i<=q;i++)cin>>v>>x,v?(g[v].push_back({x,i}),0):(ans[i]=1);
	for(int i=1;i<(1<<m);i++){int mn=1e9;
		for(int j=0;j<m;j++)if(i>>j&1&&s[j]<mn)mn=s[hs[i]=j];e[i^1<<hs[i]].push_back(i);
	}iota(fa,fa+1+n,0),fill(siz,siz+1+n,1);
	for(int i=0;i<m;i++)dfs(1<<i);for(int i=1;i<=q;i++)cout<<ans[i]<<"\n";
}
